package com.a214.yxz.yuejian013.Activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageButton;
import android.widget.Toast;

import com.a214.yxz.yuejian013.Base.BaseSActivity;
import com.a214.yxz.yuejian013.JavaBean.ShaituBean;
import com.a214.yxz.yuejian013.Listener.ServiceListener;
import com.a214.yxz.yuejian013.Model.ResModel;
import com.a214.yxz.yuejian013.R;
import com.a214.yxz.yuejian013.Activity.ShowDetailActivity;
import com.a214.yxz.yuejian013.Adapter.ShaituListAdapter;

import java.util.List;

public class UserPostActivity extends BaseSActivity {

    private ImageButton return_btn;
    private RecyclerView recyclerView;
    private RecyclerView.LayoutManager layoutManager;
    private ResModel model=new ResModel("gson",getSessionID());
    private ServiceListener<List<ShaituBean>> listener;
    private ShaituListAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user_post);
        return_btn= (ImageButton) findViewById(R.id.user_post_return_btn);
        recyclerView = (RecyclerView) findViewById(R.id.user_post_list);
        adapter=new ShaituListAdapter(UserPostActivity.this);
        layoutManager=new LinearLayoutManager(UserPostActivity.this);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setAdapter(adapter);

        listener=new ServiceListener<List<ShaituBean>>() {
            @Override
            public void onResponse(final List<ShaituBean> l) {
                adapter.setList(l);
                adapter.setOnItemClickListener(new ShaituListAdapter.OnItemClickListener() {
                    @Override
                    public void onItemClick(View view, int position) {
                        Intent intent=new Intent(UserPostActivity.this, ShowDetailActivity.class);
                        intent.putExtra("show_id", l.get(position).getId());
                        UserPostActivity.this.startActivity(intent);
                    }

                    @Override
                    public void onItemLongClick(View view, int position) {

                    }
                });
            }

            @Override
            public void onFail(String msg) {
                Toast.makeText(UserPostActivity.this, msg, Toast.LENGTH_SHORT).show();
            }
        };


        return_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        //model.getList("shaitu",getUserId(),1,"",listener);
        model.getList("shaitu","123",1,"",listener);
    }
}
